<?php $this->load->view('navmenu');?>
<?php
	$atts = array(
            'width'      => '1024',
            'height'     => '768',
            'scrollbars' => 'yes',
            'status'     => 'yes',
            'resizable'  => 'yes',
            'screenx'    => '0',
            'screeny'    => '0'
            );
?>
<script type="text/javascript" charset="utf-8">
    // dynamic table
    jQuery('#dyntable').dataTable({
    "sPaginationType": "full_numbers",
    "aaSortingFixed": [[0,'asc']],
    "fnDrawCallback": function(oSettings) {
    jQuery.uniform.update();
    }
    });
</script>
<div class="maincontent">
        	<div class="contentinner">
			<?php
			if($this->session->userdata('level')==2 AND count($approvals) < 1)
			{
			?>
				 <ul class="list-nostyle list-inline">
				 <?php //echo $projectId;?>
                                            <li><a href="<?php echo base_url();?>index.php/project/addThread/<?php echo $projectId;?>" class="btn btn-default btn-rounded"><i class="iconfa-upload"></i> Add New OR Add Revision</a></li>
                 </ul>
			<?php
			}
			?>
            	<h4 class="widgettitle">Work Progress</h4>
            	<table class="table table-bordered" id="dyntable">
                    <thead>
                        <tr>
                            <th class="center">No</th>
                            <th class="center">Subject</th>
                            <th class="center">To</th>
                            <th class="center">Drawing Title</th>
                            <th class="center">Drawing Number</th>
                            <th class="center">Location</th>
                            <th class="center">Tanggal</th>
                            <th class="center">Status</th>
                            <th class="center">Action</th>
                        </tr>
                    </thead>
                    <tbody>
					<?php $i=1;?>
					<?php foreach($threads as $row):?>
					<?php
					$countApprove = 0;
					$countROW = 0;
					foreach($approvals as $approve)
					{
						if($approve['id_sd_thread'] == $row['id_sd_thread'])
						{
							$countApprove++;
						}
					}
					?>
					<?php $jmlRow = count($threads);?>
                        <tr class="gradeX">
                            <td class="center"><?=$i?></td>
                            <td class="center"><?=$row['subject']?></td>
                            <td class="center"><?=$row['kepada']?></td>
                            <td class="center"><?=$row['draw_title']?></td>
                            <td class="center"><?=$row['draw_number']?></td>
                            <td class="center"><?=$row['location']?></td>
                            <td class="center"><?=$row['date']?></td>
                            <td class="center"><?=$row['status']?></td>
                            <td class="center">
							<a href="<?php echo base_url();?>index.php/project/showThread/<?=$row['id_sd_thread']?>"/><i class="btn btn-success btn-rounded">Check Shop Drawing</i></a></a>
							<?php if($countApprove > 0 ){?><a href="<?php echo base_url();?>index.php/project/showApproval/<?=$row['id_sd_thread']?>"/><i class="btn btn-success btn-rounded">Check Approval Shop Drawing</i></a></a><?php }?>
												<?php
												if($row['approved_by_konsultan'] ==  "APPROVED" AND $row['approved_by_mp'] == "APPROVED" AND $countApprove == 0 AND $this->session->userdata('level')==3)
												{?>
												<a href="<?php echo base_url();?>index.php/project/addApproval/<?=$row['id_sd_thread']?>"/><i class="btn btn-info btn-rounded">Upload Approval Submital Shop Drawing</i></a>
												<?php 
												} 
												elseif($row['approved_by_konsultan'] ==  "APPROVED" AND $row['approved_by_mp'] == "APPROVED" AND $countApprove == 1  AND $this->session->userdata('level')==3 AND $is_having_ig!=1)
												{
												?>
												<?php echo anchor_popup('project/addIG/'.$row['id_sd_thread'], '<i class="btn btn-default btn-rounded">Add Inspection Guide</i>', $atts); ?>
												<?php
												}												
												elseif($row['approved_by_konsultan'] ==  "APPROVED" AND $row['approved_by_mp'] == "APPROVED" AND $countApprove == 1 AND $is_having_ig == 1)
												{
												?>
												<?php echo anchor_popup('project/showIG/'.$row['id_sd_thread'], '<i class="btn btn-success btn-rounded">Show Inspection Guide</i>', $atts); ?>
												<?php 
												;
												} 
												?>
												<?php 
												if(($row['approved_by_konsultan'] ==  "REJECT" OR $row['approved_by_mp'] == "REJECT") AND $this->session->userdata('level')==2 AND $jmlRow==$i) 
												{ 
												?>
												<a href="<?php echo base_url();?>index.php/project/addThread/<?php echo $projectId;?>" class="btn btn-default btn-rounded"><i class="iconfa-upload"></i> Add Revision</a>
												<?php 
												}
												?>
												
												<?php
												if($is_having_ig == 1)
												{
												?>
												<a href="<?php echo base_url();?>index.php/project/listROW/<?php echo $projectId;?>"><i class="btn btn-success btn-rounded">Check Request Of Work</i></a>
												<?php
												}
												?>
												</td>
                        </tr>
					<?php $i++;endforeach; ?>
                    </tbody>
                </table>
            </div><!--contentinner-->
        </div><!--maincontent-->